import { create } from 'zustand';
import { Key } from 'antd/es/table/interface';
import { CarInfo } from '#/entity.ts';

interface RealTimeMonitoringStore {
  // for map
  addMarkerList: CarInfo[];
  removeMarkerList: Key[];
  singleAddMarker?: CarInfo;
  addedMarkerList: Key[];
  // for video
  videoCarNo?: CarInfo; // selected car
  actions: {
    // for map
    setAddMarkerList: (list: CarInfo[]) => void;
    setRemoveMarkerList: (list: Key[]) => void;
    setSingleAddMarker: (carInfo?: CarInfo) => void;
    setAddedMarkerList: (list: Key[]) => void;
    // for video
    setVideoCarNo: (carInfo?: CarInfo) => void;
  };
}

const realTimeMonitoringStore = create<RealTimeMonitoringStore>((set) => ({
  addMarkerList: [],
  removeMarkerList: [],
  singleAddMarkerList: undefined,
  addedMarkerList: [],
  //
  videoCarNo: undefined,
  actions: {
    // for map
    setAddMarkerList: (list) => set({ addMarkerList: list }),
    setRemoveMarkerList: (list) => set({ removeMarkerList: list }),
    setSingleAddMarker: (carInfo) => set({ singleAddMarker: carInfo }),
    setAddedMarkerList: (list) => set({ addedMarkerList: list }),
    //
    setVideoCarNo: (carInfo) => set({ videoCarNo: carInfo }),
  },
}));

export const useVideoCarNo = () => realTimeMonitoringStore((state) => state.videoCarNo);
export const useSetVideoCarNo = () =>
  realTimeMonitoringStore((state) => state.actions.setVideoCarNo);
// for map
export const useAddMarkerList = () => realTimeMonitoringStore((state) => state.addMarkerList);
export const useSetAddMarkerList = () =>
  realTimeMonitoringStore((state) => state.actions.setAddMarkerList);
export const useRemoveMarkerList = () => realTimeMonitoringStore((state) => state.removeMarkerList);
export const useSetRemoveMarkerList = () =>
  realTimeMonitoringStore((state) => state.actions.setRemoveMarkerList);
export const useSingleAddMarker = () => realTimeMonitoringStore((state) => state.singleAddMarker);
export const useSetSingleAddMarker = () =>
  realTimeMonitoringStore((state) => state.actions.setSingleAddMarker);
export const useAddedMarkerList = () => realTimeMonitoringStore((state) => state.addedMarkerList);
export const useSetAddedMarkerList = () =>
  realTimeMonitoringStore((state) => state.actions.setAddedMarkerList);

export default realTimeMonitoringStore;
